package newcoder_exp.justPractise;

import org.junit.Test;

public class NC32 {
    public int sqrt (int x) {
        if (x <= 1) return 0;
        int lo = 0, hi = x, t;
        while (lo < hi) {
            int mid = (hi - lo) / 2 + lo;
            if (mid <= x / mid && (mid + 1) > x / (mid + 1)) {
                return mid;
            } else if (mid < x / mid) {
                lo = mid + 1;
            } else {
                hi = mid - 1;
            }
        }
        return lo;
    }

    public int fact(int x) {
        return x * x;
    }

    @Test
    public void test() {
        System.out.println(sqrt(22));
    }
}
